// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const dictRequest = {
    // dict请求的基本url
    BASE_URL : confing.SYS_URL + "/dict",

    // 生成生产工单编号
    genWorkOrderId(callback){
        request.get("http://localhost:8080/gen",callback);
    },

    /**
     * 保存字典信息
     * @param {*} dict 
     * @param {*} callback 
     */
    save(dict,callback){
        if(dict){
            request.post(this.BASE_URL + "/save",dict,callback);
        }
    },
    // 请求的API
    list(page = 1,limit = 10,dict,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(dict){
            if(dict.dictName){
                url += "&dictName=" + dict.dictName;
            }
            if(dict.dictType){
                url += "&dictType=" + dict.dictType;
            }
            if(dict.dictStatus){
                url += "&dictStatus=" + dict.dictStatus;
            }
        }
        // 发送请求
        request.get(url,callbcak);
    }
}

// 将dictRequest暴漏出去
export default dictRequest;